package com.flash.BusinessData.controller;

import com.flash.BusinessData.entity.CashAccrued;
import com.flash.BusinessData.service.CashAccruedService;
import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 现金应收应付
 */
@RestController
public class CashAccruedController {
    @Autowired
    CashAccruedService  cashAccruedService;


    @Resource
    Dbutil dbutil;

    @RequestMapping("CashAccruedSelect")
    Map CashAccruedSelect(int page ,int limit,CashAccrued cashAccrued){
        List<CashAccrued> cashAccruedList = cashAccruedService.CashAccruedSelect(page, limit,cashAccrued);
        int i = cashAccruedService.CashAccruedCount();
        System.out.println("我是我是");
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("data",cashAccruedList);
        map.put("count",i);
        return map;

    }


    @RequestMapping("insertCashAccrued")
    int insertCashAccrued(CashAccrued cashAccrued, HttpServletRequest request){
        cashAccrued.setCashAccruedId(dbutil.getMaxId(TableIdUtil.CAID, TableNameUtil.CA, TableTimeUtil.CATime));
        HttpSession session = request.getSession();
        cashAccrued.setFundId((String) session.getAttribute("fundId"));
        int i = cashAccruedService.insertCashAccrued(cashAccrued);
        return i;
    }



    @RequestMapping("deleteCashAccrued")
    int deleteCashAccrued(String cashAccruedId){
        int i = cashAccruedService.deleteCashAccrued(cashAccruedId);
        return i;
    }

    @RequestMapping("updateCashAccrued" )
    int updateCashAccrued(CashAccrued cashAccrued){
        int i = cashAccruedService.updateCashAccrued(cashAccrued);
        return i;
    }



}
